<?php include $this->templateDir .'common/header.php';?>
<body style="padding:10px;">
<style> .roleListMain .layui-unselect span{color: dodgerblue;font-weight: bolder} </style>
<div class="yadmin-body animated fadeIn">
    <form action="" method="post" class="layui-form ">
        <input type="hidden" name="pid" value="<?php echo $this->data['mid']?>">
        <!--判断是否为子菜单页面添加的信息-->
        <?php if($this->data ){?>
            <div class="layui-form-item">
                <label class="layui-form-label">上级菜单</label>
                <div class="layui-input-block">
                    <input type="text" name="title" class="layui-input layui-bg-gray" lay-verify="required"  lay-vertype="tips" value="<?php echo $this->data['title'] ?>"   autocomplete="off" disabled="true"/>
                </div>
            </div>
        <?php } ?>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="title" lay-verify="required"  value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="ord" class="layui-input"  value=""  autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">控制器</label>
            <div class="layui-input-block">
                <input type="text" name="controller" class="layui-input"  value=""  autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法名</label>
            <div class="layui-input-block">
                <input type="text" name="method" class="layui-input"  value=""/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="ishidden" id="ishidden" lay-skin="primary" title="是否隐藏" value="1" >
                <input type="checkbox" name="status" id="status" lay-skin="primary" title="是否禁用" value="1" >
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="graceSubBtn" lay-submit="" lay-filter="*">保存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.use(['form', 'layer'], function(){
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer ;
        //添加角色操作
        form.on('submit(*)', function(data){
            //判断子菜单的编辑的时候控制器不为空 ； 主菜单可以为空
            if(data.field.pid >0 && data.field.control ==''){
                layer.alert("请输入控制器",{icon:2});
                return false;
            }

            //判断子菜单的编辑的时候方法名不为空 ； 主菜单可以为空
            if(data.field.pid > 0 && data.field.method == ""){
                layer.alert("请输入方法名称",{icon:2});
                return false;
            }

            var url = "<?php echo PG_SROOT;?>/menu/add";
            $.post(url,data.field,function (res) {
                if(res.status == 'ok') {
                    layer.msg( res.data, {icon: 1, time: 1000});
                    setTimeout(function(){parent.window.location.reload();},1000);
                }else{
                    layer.msg(res.data,{icon:2})
                }
            },"json");
            return false;
        });
    });
</script>
</body>
</html>